Snapshot Sample is a tiny application that shows how to grab the icon positions for all the files on the desktop and later restore those icon positions. This is useful for programs, like games, that switch resolutions on the fly, thereby causing havoc for the user’s desktop icons.
Snapshot Sample requires the Scriptable Finder (System 7.5 or greater) to operate.
How to Use
Run Snapshot Sample. This will create a file called “Desktop Snap” in your Preferences folder that records the position of all the icons on the desktop of your boot volume.
Go to the Finder, select an icon on the desktop, hold down the option key, and choose “Clean Up All” from the Special menu.
To restore the snapshot, run Snapshot Sample again.
How to Build
Snapshot Sample was built using the CodeWarrior Pro 1 C compiler,. You should be able to just open the project and hit Make.
How it Works
When you run Snapshot Sample, it looks it your Preferences folder for a file called “Desktop Snap”. If it doesn’t find a file, it creates it by indexing through all the items in the desktop folder, writing a record for each item. Each record contains the item name and item position. The file is terminated by a record with an empty name.
If the “Desktop Snap” file exists, it reads each record in turn, sending AppleEvents to the Finder to reposition the designated icon.
Issues
There are a couple of issues you should be aware of when using Snapshot Sample. The first is that it only snapshots the desktop of the boot volume. If you have icons on the desktop from multiple volumes, only the boot volume icons will be cleaned up. Working around this is trivial.
The second is that, although Snapshot Sample repositions the icons using Finder AppleEvents, it remembers the position of the icons by reading the Finder info records maintained by the file system. It does this because it’s faster and less code. The mapping of file system information to the Finder co-ordinates was discovered by trial and error. There’s some chance that this mapping will change in the future.
Snapshot Sample will not save or restore the position of things that are not files or folders, such as volume icons, the Trash, and the PowerTalk Catalogue or Mailbox icons. As far as I know, the only way to get the positions of these is by sending AppleEvents to the Finder.
Credits and Version History
If you find any problems with this stuff, mail <DevSupport@apple.com> with “Attn: Quinn” as the first line of your mail and I’ll try to fix them up.
Snapshot Sample is based on my Freeware utility “Snapshotter”. This is a much better user-level application. If you’re just using this sample to save your desktop icon positions, you should grab a copy of Snapshotter instead. It’s available from Info-Mac mirrors everywhere, including:
After I released it, many people asked me for the source to Snapshotter. Unfortunately I’ve never had time to clean it up, so I’ve been giving it away on a case-by-case basis. [Snapshotter has not been updated for Mac OS 8.]
Deborah Grits needed this technology for other reasons, so she took the Snapshotter source, converted it from Pascal to C, and simplified it a bit. She then passed the source back to me to ship as sample code.
1.0b3 was the first shipping version.
1.0b4 fixes the incompatibility with the Mac OS 8 Finder. Finder 8 seems to be much pickier about what class of object you ask for. In earlier versions, I was asking for a very specific class (eg cItem when specifying an item on the desktop, cQDPoint when specifying a point). This is not what AppleScript does, and Finder 8 got upset. So now, I ask for generic types of objects (cObject and cProperty) and everything works fine, for both Finder 8 and Finder 7.x. Also had to remove the “evil fudge factor” for Finder 8. Updated the project to CodeWarrior Pro 1.